﻿var i; //interval on global scope
var t; //timeout on global scope
var start = function () {
    i = setInterval(function () { console.log(Date.now());}, 3000 );

};

var clearTI = function () {
    clearInterval(i);
};

var startTimeOut = function () {
    t = setTimeout(function () { startTimeOut(); console.log("timeout!"); }, 3000);
};
var clearTO = function () {
    clearTimeout(t);

};
var myPost = function () {
    var xhr = new XMLHttpRequest();
    xhr.open("POST", "https://brilliant-fire-2547.firebaseio.com/.json", true);
    xhr.onload = function () {
        if (this.status >= 200 && this.status < 400) {
            console.log(this.response);
            setTimeout(myPost, 3000);
        }
        else {
            console.log(this.response);
        }
    };
    xhr.onerror = function () {
        console.log("Comm Error...resending in 15s");
        setTimeout(myPost, 15000);
    };
    xhr.send(JSON.stringify({ timestamp: Date.now() }));

};